package com.lnking.lnkingplace.controller;


import com.lnking.common.http.ReturnResult;
import com.lnking.lnkingplace.model.dto.isolation.support.SupportPlaceExcel;
import com.lnking.lnkingplace.model.entity.IsolationSupportPlace;
import com.lnking.lnkingplace.model.request.isolation.supportPlace.SupportPlaceAddRequest;
import com.lnking.lnkingplace.model.request.isolation.supportPlace.SupportPlaceSearchRequest;
import com.lnking.lnkingplace.model.request.isolation.supportPlace.SupportPlaceUpdateRequest;
import com.lnking.lnkingplace.service.IIsolationSupportPlaceService;
import com.lnking.starter.export.utils.ExportUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhangqt
 * @since 2022-09-21
 */
@RestController
@RequestMapping("/isolation-support-place")
@Api(tags = "支援区外隔离保障场所")
public class IsolationSupportPlaceController {

    @Resource
    IIsolationSupportPlaceService iIsolationSupportPlaceService;

    @ApiOperation(value = "导出")
    @GetMapping("export")
    public void export(SupportPlaceSearchRequest params, HttpServletResponse response) throws Exception {
        List<IsolationSupportPlace> data = (List<IsolationSupportPlace>)iIsolationSupportPlaceService.pageList(params);
        ExportUtils.export(data, response, SupportPlaceExcel.class);
    }

    @ApiOperation("导入")
    @PostMapping("import")
    public ReturnResult importExcel(@RequestParam("file") MultipartFile file) throws Exception{
        iIsolationSupportPlaceService.importExcel(file);
        return ReturnResult.success();
    }

    @ApiOperation("查询列表")
    @GetMapping("list")
    public ReturnResult getList(SupportPlaceSearchRequest params){
        return ReturnResult.success(iIsolationSupportPlaceService.pageList(params));
    }

    @ApiOperation("新增")
    @PostMapping("add")
    public ReturnResult add(@Valid @RequestBody SupportPlaceAddRequest params){
        iIsolationSupportPlaceService.add(params);
        return ReturnResult.success();
    }

    @ApiOperation("修改")
    @PostMapping("update")
    public ReturnResult update(@Valid @RequestBody SupportPlaceUpdateRequest params){
        iIsolationSupportPlaceService.update(params);
        return ReturnResult.success();
    }

    @ApiOperation("查询详情")
    @GetMapping("get-details")
    public ReturnResult getDetails(String id) {
        return ReturnResult.success(iIsolationSupportPlaceService.getById(id));
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ReturnResult delete(@PathVariable("id") String id) {
        iIsolationSupportPlaceService.removeById(id);
        return ReturnResult.success();
    }

    @ApiOperation("获取行政区域")
    @GetMapping("getRegion")
    public ReturnResult getRegion(){
        return ReturnResult.success(iIsolationSupportPlaceService.getRegion());
    }
}
